<template>
  <el-dialog title="双击选定人员" :visible.sync="visible" center>
    <el-container>
      <el-header>
        <el-col :xs="9" :sm="9" :lg="9">
          <el-input prefix-icon="el-icon-search" v-model="back_name" clearable
                    placeholder="姓名/姓名拼音首字母/身份证号/工号"></el-input>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="12">
          <el-button class="btn-search" type="primary" style="margin-left: 15px" @click="searchPerson()">搜索</el-button>
        </el-col>
      </el-header>
      <el-main style="padding: 0">
        <el-table
          :data="tableData"
          stripe
          border fit
          highlight-current-row
          v-loading="backLoading"
          @row-dblclick="selectBack"
          height="300">
          <el-table-column
            prop="sfzhm"
            label="身份证号码"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="recordno"
            label="工号"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="ssdwname"
            label="单位名称"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="name"
            label="姓名"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="lxdh"
            label="联系电话"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="zwname"
            label="职务"
            min-width="200">
          </el-table-column>
          <el-table-column
            prop="xbname"
            label="性别"
            min-width="200">
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <el-pagination
          small
          background
          layout="total,sizes,prev,pager,next,jumper"
          :total="total"
          :page-size="pageSize"
          :page-sizes="[10,20,30,50]"
          :current-page="pageNum"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          style="margin-top: 10px;"
        ></el-pagination>
      </el-footer>
    </el-container>
  </el-dialog>
</template>

<script>
  import {searchBackPerson} from '../../../api/public/searchUnit'
  import {selDictonaryValue} from '../../../api/dictionary'

  export default {
    name: 'back-person-dialog',
    data() {
      return {
        back_name: '',
        visible: false,
        total: 1000,
        pageSize: 10,
        pageNum: 1,
        tableData: []
      }
    },
    props: ['backVisible', 'backLoading'],
    watch: {
      backVisible: function (val) {
        const $this = this
        this.visible = val
        if (val) {
          this.pageSize = 10
          this.pageNum = 1
          searchBackPerson(this.pageNum, this.pageSize, this.back_name).then(res => {
            selDictonaryValue(res).then(resp => {
              $this.tableData = resp.list
              $this.total = resp.count
              $this.pageSize = resp.pageSize
              $this.$emit('update:backLoading', false)
            })
          })
        }
      },
      visible: function (val) {
        this.$emit('update:backVisible', val)
      }
    },
    methods: {
      searchPerson: function () {
        const $this = this
        $this.$emit('update:backLoading', true)
        searchBackPerson(this.pageNum, this.pageSize, this.back_name).then(res => {
          selDictonaryValue(res).then(resp => {
            $this.tableData = resp.list
            $this.total = resp.count
            $this.pageSize = resp.pageSize
            $this.$emit('update:backLoading', false)
          })
        })
      },
      selectBack: function (row, event) {
        this.$emit('backName', row)
        this.visible = false
      },
      handleCurrentChange: function (val) {
        this.pageNum = val
        this.searchPerson()
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchPerson()
      }
    }
  }
</script>

<style scoped>
  .el-header {
    padding: 0;
    border-bottom: none;
    margin-left: 5px;
  }

  .el-main {
    margin-top: 0px;
    margin-left: 5px;
  }
</style>
